home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / WebObjects / SourceCode / CalendarRadio.wo / CalendarRadio.wos < prev   
Text File  |  1996-04-23  |  5KB  |  174 lines

  1. ////////////////////////
  2. //  CalendarRadio
  3. //  by Charles Lloyd
  4. ////////////////////////
  5.  
  6. ////////////////////////
  7. //  User Settings
  8. ////////////////////////
  9. //These are here to allow the consumer to alter them as desired.
  10. id cellPadding;
  11. id cellSpacing;
  12. id borderSize;
  13. id dayFontSize;
  14. id monthFontSize;
  15. id yearFontSize;
  16. id showButtons;
  17. id cellAlignment;
  18.  
  19. //This is set to the value of the chosen RadioButton.
  20. id dayChoice;
  21.  
  22. ////////////////////////
  23. //  Internal State
  24. ////////////////////////
  25. //These maintain the state of the calendar itself.
  26. id currentCalendarDate;
  27. id currentDayArray;
  28.  
  29. //These are initialized by the WORepetition that drives the iteration.
  30. id columnIndex;
  31. id rowIndex;
  32.  
  33. ///////////////////////////////
  34. //  NSCalendarDate Extensions
  35. ///////////////////////////////
  36. - lastDayOfMonth:aCalendarDate
  37. {
  38.     // *** I'd like to make this a category of NSCalendarDate (that's why this takes aCalendarDate as an argument rather than using the instanceVar currentCalendarDate).
  39.     id aNewDate;
  40.     aNewDate = [aCalendarDate addYear:0 month:1 day:0 hour:0 minute:0
  41.                                second:0];
  42.     aNewDate = [aNewDate addYear:0 month:0 day:-1 hour:0 minute:0
  43.                           second:0];
  44.     return [aNewDate dayOfMonth];
  45. }
  46.  
  47. - initCurrentDayArray:aCalendarDate
  48. {
  49.     // *** I'd like to make this a category of NSCalendarDate (that's why this takes aCalendarDate as an argument rather than using the instanceVar currentCalendarDate).
  50.     id i;
  51.     id aDay;
  52.     id aStartDay;
  53.     id aLastDay;
  54.     id aCurrentDayArray;
  55.  
  56.     aCurrentDayArray = [NSMutableArray array];
  57.     aStartDay = [aCalendarDate dayOfWeek];
  58.     aLastDay = [self lastDayOfMonth:aCalendarDate];
  59.  
  60.     for (i=0; i<aStartDay; i++) {
  61.         [aCurrentDayArray addObject:0];
  62.     }
  63.     for (aDay=1; aDay<=aLastDay; aDay++) {        
  64.         [aCurrentDayArray addObject:aDay];
  65.     }
  66.     for (i=(i+aLastDay); i<42; i++) {
  67.         [aCurrentDayArray addObject:0];
  68.     }
  69.     return aCurrentDayArray;
  70. }
  71.  
  72. ///////////////////////////////
  73. //  Accessor Methods
  74. ///////////////////////////////
  75. - currentYear
  76. {
  77.     //This returns an int.
  78.     return [currentCalendarDate yearOfCommonEra];
  79. }
  80.  
  81. - currentMonth
  82. {
  83.     //This returns an int
  84.     return [currentCalendarDate monthOfYear];
  85. }
  86.  
  87. - initCurrentDayArray
  88. {
  89.     currentDayArray = [self initCurrentDayArray:currentCalendarDate];
  90. }
  91.  
  92. - setCurrentMonth:anInt
  93. {
  94.     //This invalidates the currentDayArray, so its set to nil.
  95.     id aYear = [self currentYear];
  96.     currentDayArray = nil;
  97.     currentCalendarDate = [NSCalendarDate dateWithYear:aYear
  98.                                                  month:anInt
  99.                                                    day:1
  100.                                                   hour:0
  101.                                                 minute:0
  102.                                                 second:0
  103.                                               timeZone:[NSTimeZone localTimeZone]];
  104. }
  105.  
  106. - setCurrentYear:anInt
  107. {
  108.     //This invalidates the currentDayArray, so its set to nil.
  109.     id aMonth = [self currentMonth];
  110.     currentDayArray = nil;
  111.     currentCalendarDate = [NSCalendarDate dateWithYear:anInt
  112.                                                  month:aMonth
  113.                                                    day:1
  114.                                                   hour:0
  115.                                                 minute:0
  116.                                                 second:0
  117.                                               timeZone:[NSTimeZone localTimeZone]];
  118. }
  119.  
  120. - currentMonthDescr
  121. {
  122.     return [currentCalendarDate descriptionWithCalendarFormat:@"%B"];
  123. }
  124.  
  125. - currentDayArray
  126. {
  127.     // *** This should be the only way to access currentDayArray since it may be invalidated at any time.  This ensures you always get a valid array.
  128.     if (!currentDayArray) {
  129.         [self initCurrentDayArray];
  130.     }
  131.     return currentDayArray;
  132. }
  133.  
  134.  
  135. - currentDay
  136. {
  137.     //This returns an int.  The rowIndex and colIndex are set by the WORepetition that drives this thing.
  138.     id aCurrentDayIndex = (rowIndex * 7) + columnIndex;
  139.     return [[self currentDayArray] objectAtIndex:aCurrentDayIndex];
  140. }
  141.  
  142. ///////////////////////////////
  143. //  Initialization
  144. ///////////////////////////////
  145. - awake
  146. {
  147.     id aCalendarDate = [NSCalendarDate date];
  148.     [self setCurrentYear:[aCalendarDate yearOfCommonEra]];
  149.     [self setCurrentMonth:[aCalendarDate monthOfYear]];
  150.     dayChoice = [aCalendarDate dayOfMonth];
  151.     cellPadding = 3;
  152.     cellSpacing = 3;
  153.     borderSize = 3;
  154.     yearFontSize = 6;
  155.     monthFontSize = 8;
  156.     dayFontSize = 6;
  157.     //set this to nil to NOT show buttons
  158.     showButtons = NO;
  159.     cellAlignment=@"right";
  160. }
  161.  
  162. ///////////////////////////////
  163. //  WOConditional Support
  164. ///////////////////////////////
  165. - doDay
  166. {
  167.     id aDay = [self currentDay];
  168.     if (aDay > 0) {
  169.         return YES;
  170.     }
  171.     return NO;
  172. }
  173.  
  174.